package pe.integracion;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.chemistry.opencmis.commons.exceptions.CmisObjectNotFoundException;
import org.junit.Assert;
import org.junit.Test;

public class AlfrescoMain {/*

	// private static String OS = System.getProperty("os.name").toLowerCase();

	IntegracionECMImpl alfresco = new IntegracionECMImpl();

	
	@Test
	public void queryForContentTest(){
		Retorno retorno = alfresco.queryForContent("luis");

		System.out.println(retorno.getCodigo());
		System.out.println(retorno.getMensaje());
		List<DocumentoInfo> ids = retorno.getDocumentoInfo();
		
		for (DocumentoInfo documentoInfo : ids) {
			Retorno retorno1 = alfresco
					.getDocument(documentoInfo.getObjectId().toString());
			
			FileOutputStream fos;
			try {
				fos = new FileOutputStream("C://tmp//"+documentoInfo.getName());
				fos.write(retorno1.getBytes());
				fos.close();
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}
		
		
		
	}
	
	@Test
	public void createDocumentTest() throws CmisObjectNotFoundException,
			Exception {
		Path path = Paths
				.get("D://lacastro//documentos//manuales//Head First jQuery.pdf");
		byte[] file = Files.readAllBytes(path);
		System.out.println(file);
		
		int resultado = alfresco.createDocument(file, "/TEST/TEST11",
				"Head First jQuery.pdf", "PDF");
		Assert.assertTrue(!"".equals(resultado));
	}
	
	@Test
	public void createDirectoryTest() throws CmisObjectNotFoundException,
			Exception {
		boolean resultado = alfresco
				.createDirectory("/TEST/TEST1/TEST2/TEST3/TEST4/TEST5/TEST6");
		Assert.assertTrue(resultado);
	}
	
	@Test	
	public void existDirectoryTest() throws CmisObjectNotFoundException,
			Exception {
		boolean resultado = alfresco.existDirectory("/TEST");
		Assert.assertTrue(resultado);
	}

	
	

	@Test
	public void existDocumentTest() throws CmisObjectNotFoundException,
			Exception {
		boolean resultado = alfresco
				.existDocument("9ab5cd5b-f7c5-4b49-af64-b14f94ecb759;1.0");
		Assert.assertTrue(!"".equals(resultado));
	}

	@Test
	public void getDocumentTest() throws CmisObjectNotFoundException, Exception {
		byte[] file = alfresco
				.getDocument("9ab5cd5b-f7c5-4b49-af64-b14f94ecb759;1.0");
		Assert.assertTrue(file != null);
		FileOutputStream fos = new FileOutputStream("C://tmp//descarga2.pdf");
		fos.write(file);
		fos.close();

	}

	@Test	
	public void deleteDirectoryTest() throws CmisObjectNotFoundException,
			Exception {
		boolean resultado = alfresco.deleteDirectory("/TEST");
		Assert.assertTrue(resultado);
	}
*/}